﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;


// http://msdn.microsoft.com/en-us/library/hh563947(v=vs.110).aspx

namespace wUniAppPCL.MVVM
{
  public class RelayCommand : ICommand
  {
    private readonly Action _handler;
    private bool _isEnabled = true;

    public RelayCommand(Action handler)
    {
      _handler = handler;
    }

    public bool IsEnabled
    {
      get { return _isEnabled; }
      set
      {
        if (value != _isEnabled)
        {
          _isEnabled = value;
          if (CanExecuteChanged != null)
          {
            CanExecuteChanged(this, EventArgs.Empty);
          }
        }
      }
    }

    public bool CanExecute(object parameter)
    {
      return IsEnabled;
    }

    public event EventHandler CanExecuteChanged;

    public void Execute(object parameter)
    {
      _handler();
    }
  }
}
